Conditions | 1 |
Paths | 1 |
Total Lines | 94 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | module.exports = function(GedcomX){ |
||
2 | |||
3 | var utils = require('../utils'), |
||
4 | AtomCommon = require('./AtomCommon'); |
||
5 | |||
6 | /** |
||
7 | * The content of an entry. |
||
8 | * |
||
9 | * @constructor |
||
10 | * @param {Object} [json] |
||
|
|||
11 | */ |
||
12 | var AtomContent = function(json){ |
||
13 | |||
14 | // Protect against forgetting the new keyword when calling the constructor |
||
15 | if(!(this instanceof AtomContent)){ |
||
16 | return new AtomContent(json); |
||
17 | } |
||
18 | |||
19 | // If the given object is already an instance then just return it. DON'T copy it. |
||
20 | if(AtomContent.isInstance(json)){ |
||
21 | return json; |
||
22 | } |
||
23 | |||
24 | this.init(json); |
||
25 | }; |
||
26 | |||
27 | AtomContent.prototype = Object.create(AtomCommon.prototype); |
||
28 | |||
29 | AtomContent._gedxClass = AtomContent.prototype._gedxClass = 'GedcomX.AtomContent'; |
||
30 | |||
31 | AtomContent.jsonProps = [ |
||
32 | 'gedcomx' |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Check whether the given object is an instance of this class. |
||
37 | * |
||
38 | * @param {Object} obj |
||
39 | * @returns {Boolean} |
||
40 | */ |
||
41 | AtomContent.isInstance = function(obj){ |
||
42 | return utils.isInstance(obj, this._gedxClass); |
||
43 | }; |
||
44 | |||
45 | /** |
||
46 | * Initialize from JSON |
||
47 | * |
||
48 | * @param {Object} |
||
49 | * @return {AtomContent} this |
||
50 | */ |
||
51 | AtomContent.prototype.init = function(json){ |
||
52 | |||
53 | AtomCommon.prototype.init.call(this, json); |
||
54 | |||
55 | if(json){ |
||
56 | this.setGedcomX(json.gedcomx); |
||
57 | } |
||
58 | return this; |
||
59 | }; |
||
60 | |||
61 | /** |
||
62 | * Set the GedcomX object |
||
63 | * |
||
64 | * @param {GedcomX} gedcomx |
||
65 | * @return {AtomContent} this |
||
66 | */ |
||
67 | AtomContent.prototype.setGedcomX = function(gedcomx){ |
||
68 | if(gedcomx){ |
||
69 | this.gedcomx = GedcomX(gedcomx); |
||
70 | } |
||
71 | return this; |
||
72 | }; |
||
73 | |||
74 | /** |
||
75 | * Get the GedcomX object |
||
76 | * |
||
77 | * @return {GedcomX} |
||
78 | */ |
||
79 | AtomContent.prototype.getGedcomX = function(){ |
||
80 | return this.gedcomx; |
||
81 | }; |
||
82 | |||
83 | /** |
||
84 | * Export the object as JSON |
||
85 | * |
||
86 | * @return {Object} JSON object |
||
87 | */ |
||
88 | AtomContent.prototype.toJSON = function(){ |
||
89 | return this._toJSON(AtomCommon, AtomContent.jsonProps); |
||
90 | }; |
||
91 | |||
92 | GedcomX.AtomContent = AtomContent; |
||
93 | |||
94 | }; |